﻿using System;
using System.IO;

namespace QDasTransfer.Classes
{
    public class DateTimeHelper
    {
        /// <summary>
        /// Returns a unique name with time tick added. If existed, four-digit millisecond will be appended.
        /// </summary>
        /// <param name="inputfile"></param>
        /// <returns></returns>
        public static string AppendFullDateTime(String inputfile)
        {
            string dir = Path.GetDirectoryName(inputfile);
            string filename = Path.GetFileNameWithoutExtension(inputfile);
            string ext = Path.GetExtension(inputfile);

            string outputfile = dir + "\\" + filename + "_" + ToDTString(DateTime.Now) + ext;

            while (File.Exists(outputfile)) 
                outputfile = dir + "\\" + filename + "_" + DateTime.Now.ToString("yyyyMMddHHmmssffff")  + ext;
 
            return outputfile;
        }
  



        /// <summary>
        /// 给定日期，返回字符串，格式为：2013-04-09 22:52:35 -> 20130409225235
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static string ToDTString(DateTime dt)
        {
			return dt.ToString("yyyyMMddHHmmss");
        }


		/// <summary>
		/// 给定日期，返回字符串，格式为：2013-04-09 22:52:35 -> 20130409225235
		/// </summary>
		/// <param name="dt"></param>
		/// <returns></returns>
		public static string ToDTString()
		{
			return DateTime.Now.ToString("yyyyMMddHHmmss");

		}
	}
}
